﻿/* ================================================================================
<copyright file="ExceptionRenderer.cs" company="The Framework Factory, LLC" lastWriteTime="12/05/2012 23:23:47 PM">
  Copyright (c) 2012 The Framework Factory, LLC.  All rights reserved.
</copyright>
=================================================================================== */
using System;
using System.IO;

using log4net.ObjectRenderer;

namespace FWF.Logging
{
    /// <summary>
    /// 
    /// </summary>
    public class ExceptionRenderer : IObjectRenderer
    {

        /// <summary>
        /// Render the object <paramref name="obj"/> to a string
        /// </summary>
        /// <param name="rendererMap">The map used to lookup renderers</param>
        /// <param name="obj">The object to render</param>
        /// <param name="writer">The writer to render to</param>
        /// <remarks>
        ///   <para>
        /// Render the object <paramref name="obj"/> to a
        /// string.
        /// </para>
        ///   <para>
        /// The <paramref name="rendererMap"/> parameter is
        /// provided to lookup and render other objects. This is
        /// very useful where <paramref name="obj"/> contains
        /// nested objects of unknown type. The <see cref="M:log4net.ObjectRenderer.RendererMap.FindAndRender(System.Object,System.IO.TextWriter)"/>
        /// method can be used to render these objects.
        /// </para>
        /// </remarks>
        public void RenderObject( RendererMap rendererMap, object obj, TextWriter writer )
        {
            var ex = obj as Exception;

            if ( ex != null )
            {
                writer.Write( ExceptionLib.FormatException( ex ) );
            }
        }

    }
}
